﻿using System.Web.Mvc;
using nanoCMS.Core;
using nanoCMS.Core.Concrete;
using nanoCMS.Core.Providers;
using nanoCMS.Core.WebProviders;

namespace nanoCMS.WebUI.Controllers {
	public class HomeController : Controller {
		private readonly WorldContext _worldContext;

		public HomeController(WorldContext worldContext) {
			_worldContext = worldContext;
		}
		
		[Core.WebProviders.MainActionFilter]
		public ActionResult Index(string link) {
			
			PageProvider pageProvider = new PageProvider(_worldContext);
			var model = pageProvider.GetDisplayData(link);


			if (RequestItems.Redirect != null)
			{
				return Redirect(RequestItems.Redirect);
			}
			return View(model);
		}

		public ActionResult LogOnDex() {
			User user;
			_worldContext.UserProvider.LogOn("dex@kset.org", "3008985G", out user);
			return RedirectToAction("Index");
		}

		public ActionResult HandleNonAuthorized()
		{
			return Content("Non authorized");
		}
	}
}
